package cn.tp.ksoft.civil_driver.request;

import android.content.Context;
import android.os.Handler;

import cn.tp.ksoft.civil_driver.bean.ResultBean;
import cn.tp.ksoft.civil_driver.utils.Constants;
import okhttp3.Call;

/**
 * Created by zhusong on 16/5/4.
 */
public class DriverOrderRequest extends BaseRequest implements RequestModules {
    public DriverOrderRequest(Context context, Handler handler) {
        super(context, handler);
    }
    //确认订单
    public void confirmOrder(final Long orderId) {
    	 if (checkRecycle()) {
             return;
         }
         mParams = new RequestParams();
         mParams.setServer_ip(Constants.REQUEST_SERVER_IP);
         mParams.setProject_name(Constants.REQUEST_PROJECT);
         mParams.setModel_name(Constants.REQUEST_MODEL);
         mParams.setServlet_name("driver/order/confirm.action");
         mParams.setShowProgress(true);
         mParams.setContext(mContext.get());
         mParams.addParams("orderId", orderId);
         doRequest(new SimpleProgressCall(mHandler, REQUEST_ORDER_COFIRM) {
             @Override
             public void onResponse(ResultBean response) {
                 response.setData(orderId);
                 super.onResponse(response);
             }
             @Override
             public void onError(Call call, Exception e) {
                 super.onError(call, e);
             }
         });
    }
    //删除订单(已完成)
    public void deleteOrder(final Long orderId) {
    	 if (checkRecycle()) {
             return;
         }
         mParams = new RequestParams();
         mParams.setServer_ip(Constants.REQUEST_SERVER_IP);
         mParams.setProject_name(Constants.REQUEST_PROJECT);
         mParams.setModel_name(Constants.REQUEST_MODEL);
         mParams.setServlet_name("driver/order/delete.action");
         mParams.setShowProgress(false);
         mParams.setContext(mContext.get());
         mParams.addParams("orderId", orderId);
         doRequest(new SimpleProgressCall(mHandler, REQUEST_ORDER_DELETE) {
             @Override
             public void onResponse(ResultBean response) {
                 response.setData(orderId);
                 super.onResponse(response);

             }
             @Override
             public void onError(Call call, Exception e) {
                 super.onError(call, e);
             }
         });
    }
    //完成订单
    public void finishOrder(Long orderId, Integer serLong, Double otherFee) {
    	 if (checkRecycle()) {
             return;
         }
         mParams = new RequestParams();
         mParams.setServer_ip(Constants.REQUEST_SERVER_IP);
         mParams.setProject_name(Constants.REQUEST_PROJECT);
         mParams.setModel_name(Constants.REQUEST_MODEL);
         mParams.setServlet_name("driver/order/finish.action");
         mParams.setShowProgress(true);
         mParams.setContext(mContext.get());
         mParams.addParams("orderId", orderId);
 		mParams.addParams("serLong", serLong);
 		mParams.addParams("otherFee", otherFee);
         doRequest(new SimpleProgressCall(mHandler, REQUEST_ORDER_FINISH) {
             @Override
             public void onResponse(ResultBean response) {
                 super.onResponse(response);
             }
             @Override
             public void onError(Call call, Exception e) {
                 super.onError(call, e);
             }
         });
    }
    //获取指定类型的最新订单数据
    public void getLastestFlightOrder(int type) {
        if (checkRecycle()) {
            return;
        }
        mParams = new RequestParams();
        mParams.setServer_ip(Constants.REQUEST_SERVER_IP);
        mParams.setProject_name(Constants.REQUEST_PROJECT);
        mParams.setModel_name(Constants.REQUEST_MODEL);
        mParams.setServlet_name("driver/order/latestlist.action");
        mParams.setShowProgress(false);
        mParams.setContext(mContext.get());
		mParams.addParams("timestamp", 0L);
		mParams.addParams("type", type);
        doRequest(new SimpleProgressCall(mHandler, GETLASTESTFLIGHTORDER) {
            @Override
            public void onResponse(ResultBean response) {
                super.onResponse(response);
            }

            @Override
            public void onError(Call call, Exception e) {
                super.onError(call, e);
            }
        });
    }
    //分页获取指定类型的订单数据
    public void list(long timestamp, int pageSize, int type) {
    	 if (checkRecycle()) {
             return;
         }
         mParams = new RequestParams();
         mParams.setServer_ip(Constants.REQUEST_SERVER_IP);
         mParams.setProject_name(Constants.REQUEST_PROJECT);
         mParams.setModel_name(Constants.REQUEST_MODEL);
         mParams.setServlet_name("driver/order/list.action");
         mParams.setShowProgress(false);
         mParams.setContext(mContext.get());
 		mParams.addParams("timestamp", timestamp);
 		mParams.addParams("pageSize", pageSize);
 		mParams.addParams("type", type);
         doRequest(new SimpleProgressCall(mHandler, REQUEST_ORDER_LIST) {
             @Override
             public void onResponse(ResultBean response) {
                 super.onResponse(response);
             }
             @Override
             public void onError(Call call, Exception e) {
                 super.onError(call, e);
             }
         });
    }
    //首页获取待接单、已接单列表
    public void listDriver() {
        if (checkRecycle()) {
            return;
        }
        mParams = new RequestParams();
        mParams.setServer_ip(Constants.REQUEST_SERVER_IP);
        mParams.setProject_name(Constants.REQUEST_PROJECT);
        mParams.setModel_name(Constants.REQUEST_MODEL);
        mParams.setServlet_name("driver/order/indexlist.action");
        mParams.setShowProgress(false);
        mParams.setContext(mContext.get());
        doRequest(new SimpleProgressCall(mHandler, LISTDRIVER) {
            @Override
            public void onResponse(ResultBean response) {
                super.onResponse(response);
            }
            
            @Override
            public void onError(Call call, Exception e) {
                super.onError(call, e);
            }
        });
    }
    //接到客户
    public void recCustom(Long orderId) {
    	 if (checkRecycle()) {
             return;
         }
         mParams = new RequestParams();
         mParams.setServer_ip(Constants.REQUEST_SERVER_IP);
         mParams.setProject_name(Constants.REQUEST_PROJECT);
         mParams.setModel_name(Constants.REQUEST_MODEL);
         mParams.setServlet_name("driver/order/reccustom.action");
         mParams.setShowProgress(true);
         mParams.setContext(mContext.get());
         mParams.addParams("orderId", orderId);
         doRequest(new SimpleProgressCall(mHandler, REQUEST_ORDER_START) {
             @Override
             public void onResponse(ResultBean response) {
                 super.onResponse(response);
             }
             @Override
             public void onError(Call call, Exception e) {
                 super.onError(call, e);
             }
         });
    }
    //拒绝订单
    public void refuseOrder(Long orderId, String reason) {
    	 if (checkRecycle()) {
             return;
         }
         mParams = new RequestParams();
         mParams.setServer_ip(Constants.REQUEST_SERVER_IP);
         mParams.setProject_name(Constants.REQUEST_PROJECT);
         mParams.setModel_name(Constants.REQUEST_MODEL);
         mParams.setServlet_name("driver/order/refuse.action");
         mParams.setShowProgress(false);
         mParams.setContext(mContext.get());
         mParams.addParams("orderId", orderId);
         mParams.addParams("reason", reason);
         doRequest(new SimpleProgressCall(mHandler, REQUEST_ORDER_REFUSE) {
             @Override
             public void onResponse(ResultBean response) {
                 super.onResponse(response);
             }
             @Override
             public void onError(Call call, Exception e) {
                 super.onError(call, e);
             }
         });
    }

}
